angular.module('city-data',['ngStorage'])

.controller 'cityDataCtrl', ($scope,$http,$state,areaData, showToast,$stateParams,$ionicHistory,$ionicScrollDelegate,userData,$localStorage) ->
    $scope.cityData = areaData.cityList
    $scope.province = $stateParams.provinceData
    console.log $stateParams.provinceData
    $scope.addressInfo = $localStorage.get 'addressInfo'
    getCity = ()->
        $scope.currentCity = []
        _.each $scope.cityData,(item)->
            if item.provinceid == $scope.province.provinceid
                $scope.currentCity.push item
        console.log $scope.currentCity
    $scope.goBack=()->
        $ionicHistory.goBack()

    _.extend $scope,
        confirm:(item) ->
            areaData.province=$scope.province
            areaData.city=item
            if $ionicHistory.backView()?.stateName=='tab.province-data-myself'
                $ionicHistory.goBack(-2)
            else
                $ionicHistory.goBack()
    $scope.$on '$ionicView.enter', ->
        getCity()
